//
//  UITextField+Utils.m
//  KKMY2_U
//
//  Created by 黄磊 on 14-8-4.
//  Copyright (c) 2014年 jiulong.zhou. All rights reserved.
//

#import "UITextField+Utils.h"

@implementation UITextField (Utils)

- (int)minLength
{
    return 1;
}

- (void)setMinLength:(int)minLength
{
    LogInfo(@"This function need be overwrite by [%@]", NSStringFromClass([self class]));
}

- (int)maxLength
{
    return 0;
}

- (void)setMaxLength:(int)maxLength
{
    LogInfo(@"This function need be overwrite by [%@]", NSStringFromClass([self class]));
}

- (NSString *)inputDescribe
{
    return nil;
}

- (void)setInputDescribe:(NSString *)inputDescribe
{
    LogInfo(@"This function need be overwrite by [%@]", NSStringFromClass([self class]));
}

- (BOOL)inhibitingInput
{
    return NO;
}

- (void)setInhibitingInput:(BOOL)inhibitingInput
{
    LogInfo(@"This function need be overwrite by [%@]", NSStringFromClass([self class]));
}

- (NSString *)checkContent
{
    // 检查是否为空
    NSString *descreibe = self.inputDescribe?:@"内容";
    if (self.text.length == 0) {
        return [NSString stringWithFormat:@"%@不能为空", descreibe];
    }
    // 检查是否全为空格
    if ([self.text stringByReplacingOccurrencesOfString:@" " withString:@""].length <= 0) {
        return [NSString stringWithFormat:@"%@不能全为空格", descreibe];
    }
    // 检查长度
    if (self.text.length < self.minLength) {
        return [NSString stringWithFormat:@"%@长度不得小于%d个字符", descreibe, self.minLength];
    }
    if (self.text.length > self.maxLength) {
        return [NSString stringWithFormat:@"%@长度不得超过%d个字符", descreibe, self.maxLength];
    }
    // 检查特殊字符
    if ([NSString isContainsEmoji:self.text]) {
        return [NSString stringWithFormat:@"%@暂不支持表情或特殊字符", descreibe];
    }
    return nil;
}

@end
